﻿
Imports DotNetNuke
Imports DotNetNuke.Entities.Modules
Imports System.Web.UI
Imports DotNetNuke.Entities.Modules.Actions
Imports Telerik.Web
Imports Telerik.Web.UI

Namespace dnnWerk.Modules.Users


    Partial Class UserModule
        Inherits UserModuleBase
        Implements IActionable

#Region "Private Members"

        Private _controltoload As String = ""
        Private _applyskin As Boolean = True

#End Region

#Region "Public Members"

        Public ReadOnly Property ModuleActions() As DotNetNuke.Entities.Modules.Actions.ModuleActionCollection Implements DotNetNuke.Entities.Modules.IActionable.ModuleActions
            Get
                Dim Actions As New ModuleActionCollection
                If DotNetNuke.Security.PortalSecurity.HasNecessaryPermission(SecurityAccessLevel.Admin, PortalSettings, Me.ModuleConfiguration, UserInfo) Then
                    Actions.Add(GetNextActionID, "User Module Settings", ModuleActionType.AddContent, "", "dnrt.gif", NavigateURL(TabId, "", "uctrl=Settings"), False, DotNetNuke.Security.SecurityAccessLevel.Edit, True, False)
                End If
                Return Actions
            End Get
        End Property

#End Region

#Region "Event Handlers"

        Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

            LoadSettings()
            BindCss()

        End Sub

        Private Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles Me.PreRender

            ApplySkin(plhControls)

        End Sub

        Public Sub ApplySkin(ByVal target As Control)

            If Not target.Visible Then
                Exit Sub
            End If

            If TypeOf target Is ISkinnableControl Then

                DirectCast(target, ISkinnableControl).Skin = ControlSkin
                DirectCast(target, ISkinnableControl).EnableEmbeddedBaseStylesheet = True
                DirectCast(target, ISkinnableControl).EnableEmbeddedSkins = True

                For Each child As Control In target.Controls
                    ApplySkin(child)
                Next

            Else

                If _applyskin Then

                    If TypeOf target Is RadPageView Then
                        DirectCast(target, RadPageView).CssClass += " " & ControlSkin
                    End If

                    If TypeOf target Is Panel Then
                        Dim pnl As Panel = DirectCast(target, Panel)
                        pnl.CssClass += " " & ControlSkin
                    End If

                    If TypeOf target Is LinkButton Then
                        Dim cmd As LinkButton = DirectCast(target, LinkButton)
                        cmd.CssClass += " " & ControlSkin
                    End If

                End If


                For Each child As Control In target.Controls
                    ApplySkin(child)
                Next

            End If

        End Sub

#End Region

#Region "Private Methods"

        Private Sub BindCss()
            'Dim strCss As String = "<link href=""" & Me.ModuleDirectory.Replace("~", "") & "/module.css"" rel=""stylesheet"" type=""text/css"" />"
            'Try
            '    Me.Page.FindControl("Head").Controls.Add(New LiteralControl(strCss))
            'Catch
            'End Try
        End Sub

        Private Sub LoadSettings()

            If Not Request.QueryString("uctrl") Is Nothing Then

                If Request.QueryString("uctrl") = "Settings" Then
                    _controltoload = Me.TemplateSourceDirectory & "/uc_Settings.ascx"
                    _applyskin = False
                End If

            Else

                If Not Settings("ControlToLoad") Is Nothing Then
                    Select Case Settings("ControlToLoad")
                        Case "Memberlist"
                            _controltoload = Me.TemplateSourceDirectory & "/uc_Memberlist.ascx"
                        Case "UserRegister"
                            _controltoload = Me.TemplateSourceDirectory & "/uc_Register.ascx"
                        Case "UserProfile"
                            _controltoload = Me.TemplateSourceDirectory & "/uc_Profile.ascx"
                        Case "ManageUsers"
                            _controltoload = Me.TemplateSourceDirectory & "/uc_Manage.ascx"
                    End Select
                Else
                    _controltoload = Me.TemplateSourceDirectory & "/uc_Settings.ascx"
                    _applyskin = False
                End If

            End If

            LoadControlType()

        End Sub

        Private Sub LoadControlType()

            Dim objPortalModuleBase As PortalModuleBase = CType(Me.LoadControl(_controltoload), PortalModuleBase)
            objPortalModuleBase.ModuleConfiguration = Me.ModuleConfiguration
            objPortalModuleBase.ID = System.IO.Path.GetFileNameWithoutExtension(_controltoload)
            ' Load the appropriate control
            '
            plhControls.Controls.Add(objPortalModuleBase)

        End Sub



#End Region


    End Class

End Namespace

